<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>新增员工</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../bangnuo/admin/layui/css/layui.css" media="all">
</head>

<body>

<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin"
     style="padding: 20px 0 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">登录名</label>
        <div class="layui-input-inline">
            <input type="text" name="adminUsername" lay-verify="required" placeholder="请输入用户名" autocomplete="off"
                   class="layui-input">
            <br/>
            <!--<div class="layui-form-mid layui-word-red" style="color: red;">密码默认为：a88888</div>-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">登录密码</label>
        <div class="layui-input-inline">
            <input type="text" name="adminPassword" lay-verify="required" placeholder="请输入登录密码" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">真实姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="adminName" lay-verify="required" placeholder="请输入真实姓名" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号码</label>
        <div class="layui-input-inline">
            <input type="text" name="adminPhone" id="adminPhone" lay-verify="phone" placeholder="请输入号码" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-inline">
            <input type="text" name="adminEmail" id="adminEmail" lay-verify="email" placeholder="请输入邮箱" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" lay-filter="sex">
        <label class="layui-form-label">选择性别</label>
        <div class="layui-input-block">
            <input type="radio" name="adminSex" value="男" title="男" checked>
            <input type="radio" name="adminSex" value="女" title="女">
        </div>
    </div>
    <div class="layui-form-item" lay-filter="sex">
        <label class="layui-form-label">所属代理</label>
        <div class="layui-input-block" style="width: 200px;">
            <select name="adminIdAgentId" id="adminIdAgentId">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block" style="padding-bottom: 10px; margin-left: 110px; margin-right: -110px;">
            <button class="layui-btn" lay-submit lay-filter="formDemo" data-type="close">立即提交</button>
        </div>
    </div>
</div>
<script src="../../../bangnuo/admin/layui/layui.js"></script>
<script src="../../../bangnuo/admin/js/jquery-1.8.0.min.js"></script>
<script>
    $("#adminPhone").blur(function () {
        var phone = /^[1][3,4,5,7,8][0-9]{9}$/; //"请输入正确的手机号"
        if(!phone.test($("#adminPhone").val())){
            layer.msg("请输入正确的电话号");
        }
    });
    $("#adminEmail").blur(function () {
        var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; //"邮箱格式不正确"
        if(!email.test($("#adminEmail").val())){
            layer.msg("请输入正确的邮箱号");
        }
    });
</script>
<script>
    layui.use(['form', 'upload', 'layer'], function () {

        var form = layui.form;

        var resultData;
        var htmls = '<option value="">请选择</option>'; //全局变量

        //检查项目添加到下拉框中
        $.ajax({
            url: '/agentEntity/agent',
            dataType: 'json',
            type: 'get',
            success: function (data) {
                resultData = data.queryResult.list;
                for (var x in resultData) {
                    htmls += '<option value = "' + resultData[x].id + '">' + resultData[x].name + '</option>';
                }
                $("#adminIdAgentId").html(htmls);
                form.render('select');
                //重新渲染 固定写法
            }
        })
    });
</script>
<!--加载表单组件样式-->
<script>
    layui.config({
        base: '../../../bangnuo/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'upload'], function () {
        var $ = layui.$,
            form = layui.form,
            upload = layui.upload;

        upload.render({
            elem: '#layuiadmin-upload-useradmin',
            url: layui.setter.base + 'json/upload/demo.js',
            accept: 'images',
            method: 'get',
            contentType: "application/json",
            acceptMime: 'image/*',
            done: function (res) {
                $(this.item).prev("div").children("input").val(res.data.src)
            }
        });
    })
</script>
<!--获取表单信息，提交表单-->
<script type="text/javascript">
    layui.use(['form', 'layer'], function () {
        var form = layui.form,
            layer = layui.layer,
            index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        //监听提交
        form.on('submit(formDemo)', function (data) {
            $.ajax({
                type: "post",
                url: "/adminEntity/addEmployees",
                contentType: "application/json",
                dataType: 'json',
                data: JSON.stringify(data.field),
                async: true,
                success: function (data) {
                    if (data.success == true) {
                        layer.msg(data.message);
                        $(document).ready(function () {
                            var  index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            console.log("index值",index);
                            close();
                        });
                    } else {
                        layer.msg(data.message);
                    }
                },
            });
            return false;
        });
    });
</script>
<!--关闭弹层-->
<script>
    layui.use('layer', function () {
        var $ = layui.$,
            layer = layui.layer,
            index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        var active = {
            close: function () {
                var id = '#LAY_layer_iframe_demo',
                    mark = $('#LAY_mark');
                parent.layer.msg('添加成功');
                parent.layer.tips('Look here', id, {
                    time: 5000
                });
                parent.layer.close(index);
            }
        }
        $('.layui-btn-container .layui-btn').on('click', function () {
            var othis = $(this),
                type = othis.data('type');
            active[type] && active[type].call(this);
        });
    });
</script>
</body>

</html>